
<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	<jsp:useBean class="forum.db_code" id="t" scope="request"/>
	<%
		int subforumid = Integer.parseInt(request.getParameter("subForumID"));
		String NameOfThread = request.getParameter("name");
		
		int createdBy = 1;//TODO Get ID from loggedIn user!
		
		java.sql.Timestamp createdOn = new java.sql.Timestamp(System.currentTimeMillis());
		
		int views = 0;
		int replies = 0;
		String Content = request.getParameter("content");
		
		boolean createdThread = t.createThread(subforumid, NameOfThread, createdBy, createdOn, views, replies);
		
		if(createdThread){
			int threadId = t.getThreadID()-1;
			System.out.println("threadId: " + threadId);
			if(threadId > 0){
				boolean createdPost = t.createPost(threadId, createdBy, Content, createdOn, createdOn);
				if(createdPost){
					System.out.println("createdPost = true!");
				}else
				{
					System.out.println("createdPost = false!");
				}
				if(createdThread && createdPost && threadId > 0){
					System.out.println("Yeey!");
					%>
					<p>Success!</p>
					<%
				}
				else{
					System.out.println("Fail!");
					%>
					<p>Fail!</p>
					<%
				}
			}
			else{
				System.out.println("threadId < 0!");
			}
		}else{
			System.out.println("createdThread = false!");
			%>
			<p>createdThread = false!</p>
			<%
		}
	%>


</body>
</html>